using UnityEngine;
using UnityEngine.UI;

public class BackgroundScroller : MonoBehaviour
{
    public float Speed = 1;

    private Image _renderer;

    void Start()
    {
        _renderer = transform.GetComponent<Image>();
    }

    void Update()
    {
        _renderer.material.mainTextureOffset = new Vector2(Time.time * Speed, 0);
        // 定义一个阈值
        float threshold = 100000.0f;

        if (_renderer.material.mainTextureOffset.y > threshold)
        {
            // 将纹理重新放回初始位置
            _renderer.material.mainTextureOffset = new Vector2(0, 0);
        }
    }
}

